< previous page page_277 next page >

Page 277
analysis.gifAfter a user deletes a record, that record will become invalid in the recordset, so you need to move off that record. The user has the choice of moving forward to the next record, moving backward to the previous record, or maybe moving to the first or last record. The best way to handle this is to create a routine called DataReposition to perform this movement. By creating a procedure, youll be better able to reuse this code in other forms where you need the same functionality.

EXERCISE
Create the Reposition Procedure for the Data Control
1. Create a general form procedure called DataReposition.
2. Add the following code:
Private Sub DataReposition()
With datEmployees.Recordset
.MoveNext
If .EOF Then
.MovePrevious
End If
End With
End Sub
analysis.gifIn this routine you perform a MoveNext method to move to the record after the one just deleted. After you perform a MoveNext, you might hit the end of the file. Therefore, immediately after moving to the next record, you need to check the EOF property. If youve hit the EOF, you should perform a MovePrevious method to move to a valid record.

Canceling Changes
If the user clicks the New command button or types a character into a data-bound control by mistake, he or she will need some way to cancel out of that mode without having to close the entire form. As youll remember, you toggled the Caption of the Close command button to Cancel, so in the Click event of the cmdClose button, you need to write some code to provide a way to cancel out of the adding or editing of the data.

 
< previous page page_277 next page >

If you like this book, buy it!